<template>
  <div class="app-container">
    <el-row :gutter="0" class="el-card is-always-shadow el-card__body content_h">
      <el-col class="title_top">
        <div class="title_top_E">Hospital Management</div>
        <div class="title_top_C">机构管理</div>
      </el-col>
      <el-col class="screen_case ">
        <el-row style="width: 100%;">
          <el-col :span="4">
            <div class="screen_case_amount mb20">
              <span class="screen_case_amount_lable">机构数量：</span>
              <span class="screen_case_amount_value">{{ total }}</span>
            </div>
            <construction title="新建机构" @addition="additions" class=" ml0" />
          </el-col>
          <el-col :span="5">
            <screenSelect title="机构名称" type='input' v-model="queryFrom.hospitalName" :isValue='queryFrom.hospitalName'
              placeholder="请输入机构名称" @transfer="valueHeld($event, 'hospitalName')" class="mb15" />
            <screenSelect title="机构状态" type='select' v-model="queryFrom.status" :isValue='queryFrom.status'
              placeholder="请选择" @transfer="valueHeld($event, 'status')" :options="statusoptions" class="" />
          </el-col>
          <el-col :span="12">
            <el-row>
              <el-col style="display: flex;">
                <screenSelect title="机构地区" type='select' v-model="queryFrom.province" :isValue='queryFrom.province'
                  placeholder="请选择省" @transfer="valueHeld($event, 'province')" :options="ProvinceList" class="mb15" />
                <screenSelect title="" type='select' v-model="queryFrom.city" :isValue='queryFrom.city'
                  placeholder="请选择市" @transfer="valueHeld($event, 'city')" :options="CityList" class="mb15" />
                <screenSelect title="" type='select' v-model="queryFrom.areas" :isValue='queryFrom.areas'
                  placeholder="请选择区" @transfer="valueHeld($event, 'areas')" :options="AreaList" class="mb15" />
              </el-col>
              <el-col>
                <div style="display: flex;">
                  <screenSelect title="合作类型" type='select' v-model="queryFrom.cooperationType" :isValue='queryFrom.cooperationType'
                    placeholder="请选择" @transfer="valueHeld($event, 'cooperationType')" :options="cooperationoptions" class="" />
                  <el-button type="primary" class="ch_button mb15" @click="search">
                    <img class="ch_button_img" src="../../assets/iconfont/zoom-out.png" alt="" srcset="">
                    <div>搜索</div>
                  </el-button>
                  <el-button type="primary" class="ch_button mb15" @click="reset">
                    <img class="ch_button_img" src="../../assets/iconfont/rotate-ccw.png" alt="" srcset="">
                    <div>选项重置</div>
                  </el-button>
                </div>
              </el-col>
            </el-row>
          </el-col>
        </el-row>
      </el-col>
    </el-row>
    <el-row :gutter="0" class="card_content">
      <template v-for="(item, index) in cardData">
        <smallCard :title="item.hospitalName" :operation="item.runningDays.toString()" :subhead="gradeoptions[item.grade].label"
          @clickHeld="multifunction($event, item.hospitalId)" :img="item.hospitalAvatarUrl"
          :line="item.status == 0 ? true : false" buttons="2" type="institution" />
      </template>
      <div class="paginationblock" v-if="total > 0">
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
          :current-page="pageData.pageNo" :page-sizes="[10, 20, 30, 40]" :page-size="pageData.pageSize"
          :background="true" layout="total, sizes, prev, pager, next, jumper" :total="total">
        </el-pagination>
      </div>
    </el-row>
    <el-dialog id="viewHeld" custom-class="eldialogCH" :modal="true" :visible.sync="viewHeld" :show-close='false'
      center>
      <div slot="title" class="dialog_title_ch">
        <div>
          <div class="dialog_title_ch_subheading">
            Hospital Information
          </div>
          <div class="dialog_title_ch_subhead">
            机构信息
          </div>
        </div>
        <div class="icon_x-circle" @click="viewHeld = false"></div>
        <!-- <img class="icon_x-circle" src="../../assets/iconfont/x-circle.png" alt="" @click="viewHeld = false"> -->
      </div>
      <div class="dialog_title_ch_conter" v-if="viewData">
        <div class="dialog_title_ch_conter_left">
          <img :src="viewData.hospitalAvatarUrl" alt="" srcset="" style="border-radius: 50%;">
          <div class="quan" :class="true ? 'on_line' : 'off_line'"></div>
        </div>
        <div class="dialog_title_ch_conter_right">
          <div class="postTitle">{{ viewData.hospitalName }}</div>
          <div class="postTitle_conter">
            <div class="postTitle_conter_item">
              <div class="postTitle_conter_itemspan">
                <span class="postTitle_conter_itemspan1">机构等级：</span>
                <span class="postTitle_conter_itemspan2">{{ gradeoptions[viewData.grade].label
                  }}</span>
              </div>
              <div class="postTitle_conter_itemspan">
                <span class="postTitle_conter_itemspan1">机构联系人：</span>
                <span class="postTitle_conter_itemspan2">{{ viewData.contacts }}</span>
              </div>
              <div class="postTitle_conter_itemspan">
                <span class="postTitle_conter_itemspan1">{{ viewData.settlementUnit == 2 ? '机构小时池：' :viewData.settlementUnit == 3?'机构次数池：': '机构天数池：' }}</span>
                <span
                  class="postTitle_conter_itemspan2">{{ viewData.settlementUnit == 2 ? viewData.availableHours :viewData.settlementUnit == 3?viewData.availableNum: viewData.availableDays }}</span>
              </div>
              <div class="postTitle_conter_itemspan">
                <span class="postTitle_conter_itemspan1">运行天数：</span>
                <span
                  class="postTitle_conter_itemspan2">{{viewData.runningDays}}</span>
              </div>
              <div class="postTitle_conter_itemspan">
                <span class="postTitle_conter_itemspan1">机构科室上限：</span>
                <span class="postTitle_conter_itemspan2">{{ viewData.departmentUpperLimit }}</span>
              </div>
            </div>
            <div class="postTitle_conter_item">
              <div class="postTitle_conter_itemspan">
                <span class="postTitle_conter_itemspan1">所在地区：</span>
                <span class="postTitle_conter_itemspan2">{{ viewData.provinceName }} {{ viewData.cityName }} {{
      viewData.areasName
    }}</span>
              </div>
              <div class="postTitle_conter_itemspan">
                <span class="postTitle_conter_itemspan1">联系电话：</span>
                <span class="postTitle_conter_itemspan2">{{ viewData.contactsPhone }}</span>
              </div>
              <div class="postTitle_conter_itemspan">
                <span class="postTitle_conter_itemspan1">机构运营项目：</span>
                <span class="postTitle_conter_itemspan2">{{
      operationProjectoptions[viewData.operationProject].label }}</span>
              </div>
              <div class="postTitle_conter_itemspan">
                <span class="postTitle_conter_itemspan1">科室人员上限：</span>
                <span class="postTitle_conter_itemspan2">{{ viewData.departmentPersonUpperLimit }}</span>
              </div>
            </div>
            <div class="postTitle_conter_item">
              <div class="postTitle_conter_itemspan">
                <span class="postTitle_conter_itemspan1">详细地址：</span>
                <span class="postTitle_conter_itemspan2">{{ viewData.address }}</span>
              </div>
              <div class="postTitle_conter_itemspan">
                <span class="postTitle_conter_itemspan1">当前科室数量：</span>
                <span class="postTitle_conter_itemspan2">{{ viewData.totalDepartment }}</span>
              </div>
              <div class="postTitle_conter_itemspan" v-if="viewData.operationProject != 0">
                <span class="postTitle_conter_itemspan1">设备运营类型：</span>
                <span class="postTitle_conter_itemspan2">{{
      operationTypeoptions[viewData.operationType].label }}</span>
              </div>
              <div class="postTitle_conter_itemspan">
                <span class="postTitle_conter_itemspan1">结算单位：</span>
                <span class="postTitle_conter_itemspan2">{{ viewData.settlementUnit == 2 ? '小时' :viewData.settlementUnit == 3?'次数': '天' }}</span>
              </div>
            </div>
            <div class="postTitle_conter_item">
              
              <div class="postTitle_conter_itemspan" v-if="viewData.salesPerson!=null">
                <span class="postTitle_conter_itemspan1">负责人业务员：</span>
                <span class="postTitle_conter_itemspan2">{{viewData.salesPerson}}</span>
              </div>
              <div class="postTitle_conter_itemspan" v-if="viewData.cooperationType!=null">
                <span class="postTitle_conter_itemspan1">合作类型：</span>
                <span class="postTitle_conter_itemspan2">{{cooperationoptions[viewData.cooperationType].label}}</span>
              </div>
              <div class="postTitle_conter_itemspan">
                <span class="postTitle_conter_itemspan1">创建时间：</span>
                <span class="postTitle_conter_itemspan2">{{ parseTime(viewData.createTime, '{y}.{m}.{d}') }}</span>
              </div>
              <div class="postTitle_conter_itemspan">
                <span class="postTitle_conter_itemspan1">机构简称：</span>
                <span class="postTitle_conter_itemspan2">{{ viewData.hospitalAbbreviation }}</span>
              </div>
              <div class="postTitle_conter_itemspan">
                <span class="postTitle_conter_itemspan1">机构控制方式：</span>
                <span class="postTitle_conter_itemspan2">{{
      controlTypeoptions[viewData.controlType].label }}</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import construction from '@/components/construction/index.vue'
import screenSelect from '@/components/screenSelect/index.vue'
import smallCard from '@/components/smallCard/index.vue'
import { getHospitalList, getHospitalDetail, getHospitaPagelList,getHospitalDelete } from '@/api/organizational'
import { getProvince, getCity, getArea } from '@/api/common'
import {
  mapGetters
} from 'vuex'
export default {
  name: "Field",
  components: {
    construction,
    screenSelect,
    smallCard
  },
  computed: {
    ...mapGetters([
      'permissionList'
    ])
  },
  watch: {
    'queryFrom.province': {
      handler(newVal, oldVal) {
        this.queryFrom.city = ''
        this.queryFrom.areas = ''
        if (newVal) {
          this.getCity()
        }
      }
    },
    'queryFrom.city': {
      handler(newVal, oldVal) {
        this.queryFrom.areas = ''
        if (newVal) {
          this.getArea()
        }
      }
    }
  },
  data() {
    return {
      keshi: 0,
      viewHeld: false,
      editHeld: false,
      familyHeld: false,
      gradeoptions: [{
        value: 0,
        label: '一甲'
      }, {
        value: 1,
        label: '二甲'
      }, {
        value: 2,
        label: '三甲'
      }, {
        value: 3,
        label: '二已'
      }],
      typeoptions: [
        {
          value: 0,
          label: '公立医院'
        }, {
          value: 1,
          label: '私立医院'
        }
      ],
      operationProjectoptions: [
        {
          value: 0,
          label: '自购服务'
        }, {
          value: 1,
          label: '设备服务'
        }
      ],
      operationTypeoptions: [
        {
          value: 0,
          label: '平台收款'
        }, {
          value: 1,
          label: '医院收款'
        }
      ],
      settlementUnitoptions: [
        {
          value: 0,
          label: '天数-订单扣除'
        }, {
          value: 1,
          label: '天数-实际天数扣除'
        }, {
          value: 2,
          label: '小时'
        }, {
          value: 3,
          label: '次数'
        }
      ],
      statusoptions: [
        {
          value: 0,
          label: '运营中'
        }, {
          value: 1,
          label: '停运'
        }
      ],
      cooperationoptions: [
        {
          value: 0,
          label: '销售试用中'
        }, {
          value: 1,
          label: '销售试用结束'
        }, {
          value: 2,
          label: '销售运行'
        }, {
          value: 3,
          label: '合作试用中'
        }, {
          value: 4,
          label: '合作试用结束'
        }, {
          value: 5,
          label: '合作运行'
        }
      ],
      controlTypeoptions: [
        {
          value: 0,
          label: '控制'
        }, {
          value: 1,
          label: '非控制'
        }
      ],
      cardData: [],
      imageUrl: '',
      queryFrom: {
        province: '',
        city: '',
        areas: '',
        status: '',
        hospitalName: ''
      },
      ProvinceList: [],
      CityList: [],
      AreaList: [],
      viewData: null,
      pageData: {
        pageNo: 1,
        pageSize: 10
      },
      total: 0
    };
  },
  mounted() {
    this.getList()
    this.getProvince()
  },

  methods: {
    getList() {
      let that = this
      const loading = that.$loading({
        lock: true,
        text: 'Loading...',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      });
      getHospitaPagelList(this.queryFrom, this.pageData).then(res => {
        if (res.code == 200) {
          that.cardData = res.data.hospitalPage.records
          this.total = res.data.hospitalPage.total
          loading.close();
        }
      })
    },
    getProvince() {
      getProvince().then(res => {
        if (res.code == 200) {
          res.data.provinceList.map(item => {
            item.label = item.name
            item.value = item.id
          })
          this.ProvinceList = res.data.provinceList
        }
      })
    },
    getCity() {
      getCity(this.queryFrom.province).then(res => {
        if (res.code == 200) {
          res.data.cityList.map(item => {
            item.label = item.name
            item.value = item.id
          })
          this.CityList = res.data.cityList
        }
      })
    },
    getArea() {
      getArea(this.queryFrom.city).then(res => {
        if (res.code == 200) {
          res.data.areaList.map(item => {
            item.label = item.name
            item.value = item.id
          })
          this.AreaList = res.data.areaList
        }
      })
    },
    additions() {
      this.$router.push({ path: `/organizational/organizationaledit/0` })
    },
    tabGo() {
      this.$router.go(-1)
    },
    search() {
      this.pageData={
					pageNo: 1,
					pageSize: 10
				}
      this.getList()
    },
    reset() {
      this.queryFrom = {
        province: '',
        city: '',
        areas: '',
        status: '',
        hospitalName: ''
      }
      this.getList()
    },
    valueHeld(childParam, fatherparam) {
      this.queryFrom[fatherparam] = childParam
    },
    multifunction(e, id) {
      if (e == 'familyHeld') {
        this.$router.push({ path: `/organizational/administrative/${id}` })
      } else if (e == 'editHeld') {
        this.$router.push({ path: `/organizational/organizationaledit/${id}` })
      } else if (e == 'viewHeld') {
        getHospitalDetail(id).then(res => {
          console.log(res);
          if (res.code == 200) {
            this[e] = true
            this.viewData = res.data.hospital
          }
        })
      }else if(e=='deleteHeld'){
        this.$confirm('此操作将永久删除该医院, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          getHospitalDelete(id).then(res => {
            if (res.code == 200) {
              this.$message({
                type: 'success',
                message: '删除成功!'
              });
              this.getList()
            }
          })

        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      }
    },
    handleSizeChange(val) {
      this.pageData.pageSize = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.pageData.pageNo = val
      this.getList()
    },
    handleAvatarSuccess(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw);
    },
    beforeAvatarUpload(file) {
      const isJPG = file.type === 'image/jpeg';
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isJPG) {
        this.$message.error('上传头像图片只能是 JPG 格式!');
      }
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 2MB!');
      }
      return isJPG && isLt2M;
    }

  }
}
</script>
<style lang="scss" scoped>
.app-container {
  overflow-y: auto;
}

.card_content {
  margin-top: 16px;
  height: calc(100% - 230px);
  overflow-y: auto;
}

.card_contents {
  height: calc(100% - 1px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;

  .card_contents_tex {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 20px;
  }

  .card_contents_footer {
    padding: 16px 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-top: 1px solid #EFEFEF;
  }
}

.content_h {
  min-height: 149px;
  border-radius: 5px;
  padding: 0px;
}

.title_top {
  min-height: 79px;
  border-bottom: 1px solid #EFEFEF;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  padding: 0 20px;
}

.title_tops {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0 20px;
  height: 79px;
  border-bottom: 1px solid #EFEFEF;

  .title_tops_t {
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  .title_tops_b {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 28px;
    cursor: pointer;

    img {
      width: 24px;
      height: 24px;
      margin-right: 5px;
    }

    span {
      font-size: 16px;
      font-weight: 400;
      color: #000;
    }
  }
}

.screen_case_title {
  font-size: 16px;
  font-weight: 400;
  color: #000;
  margin-right: 35px;
}

.title_top_E {
  font-size: 12px;
  font-weight: 400;
  color: #9898989E;
}

.title_top_C {
  font-size: 18px;
  font-weight: 400;
  color: #000;
}

.screen_case {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  padding: 15px 30px;
}

.screen_case_amount {
  white-space: nowrap;

  .screen_case_amount_lable {
    font-size: 15px;
    color: #989898;
  }

  .screen_case_amount_value {
    font-size: 16px;
    color: #000;
  }
}

::v-deep .el-button.ch_button {
  padding: 8px 9px;
}

::v-deep .el-button.ch_button span {
  display: flex;
  align-items: center;

  div {
    font-size: 13px;
    font-weight: 400;
    margin-left: 4px;
  }
}

#viewHeld,
#editHeld,
#familyHeld {
  display: flex;
  align-items: center;
  justify-content: center;
}

::v-deep .eldialogCH {
  border-radius: 6px;
  width: 1268px;
  margin-top: 0 !important;
  // 自定义弹窗x号
  // .el-dialog__close::before {
  //   content: ' ';
  //   background: url(../../assets/iconfont/x-circle.png);
  //   background-size: 20px 20px;
  //   width: 20px;
  //   height: 20px;
  //   display: flex;
  // }

  // .el-dialog__close:active::before {
  //   background: url(../../assets/iconfont/x-circleactive.png);
  //   background-size: 20px 20px;
  // }
}

::v-deep #editHeld .eldialogCH {
  width: 1579px;
}

::v-deep .ch_button_seav {
  padding: 7px 27px;

  span {
    display: flex;
    align-items: center;
    justify-content: center;

    div {
      font-size: 16px;
      font-weight: 400;
      margin-left: 10px;
    }
  }

}

.ch_button_img_seav {
  width: 24px;
  height: 24px;
}

.ch_button_img {
  width: 16px;
  height: 16px;
}

.dialog_title_ch {
  border-bottom: 1px solid #EFEFEF;
  padding: 25px 21px 13px 21px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.icon_x-circle {
  width: 24px;
  height: 24px;
  background: url(../../assets/iconfont/x-circle.png);
  background-size: 100% 100%;
  cursor: pointer;
}

.icon_x-circle:active {
  background: url(../../assets/iconfont/x-circleactive.png);
  background-size: 100% 100%;
  // opacity: .6;
}

::v-deep #viewHeld .el-dialog__header,
::v-deep #editHeld .el-dialog__header,
::v-deep #familyHeld .el-dialog__header {
  padding: 0 !important;
  text-align: left;
}

::v-deep #viewHeld .el-dialog__body,
::v-deep #editHeld .el-dialog__body,
::v-deep #familyHeld .el-dialog__body {
  padding: 17px 20px;
}

::v-deep #editHeld .el-dialog__footer {
  padding: 17px 20px;
  border-top: 1px solid #EFEFEF;
}

.dialog_title_ch_subheading {
  font-size: 12px;
  font-weight: 400;
  color: #9898989E;
}

.dialog_title_ch_subhead {
  font-size: 18px;
  font-weight: 400;
  color: #000;
}

.dialog_title_ch_conter_operate {
  padding: 24px 35px;
  // border: 1px solid #EBEBEB;
  border-radius: 2px;
  display: flex;
  // align-items: center;
}

.dialog_title_ch_conter {
  padding: 24px 35px;
  border: 1px solid #EBEBEB;
  border-radius: 2px;
  display: flex;
  // align-items: center;

  .dialog_title_ch_conter_left {
    position: relative;
    width: 80px;
    height: 80px;
    margin-right: 33px;

    img {
      width: 100%;
      height: 100%;
    }

    .quan {
      position: absolute;
      bottom: 0;
      right: 0;
      border: 2px solid #FFFFFF;
      width: 20px;
      height: 20px;
      border-radius: 100%;
    }
  }

  .dialog_title_ch_conter_right {
    flex: 1;
    white-space: nowrap;
  }

  .postTitle {
    font-size: 20px;
    font-weight: 400;
    margin-bottom: 8px;
    color: #000;
  }

  .postTitle_conter {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;

    .postTitle_conter_item {
      flex: 1;
      margin-right: 20px;

      .postTitle_conter_itemspan {
        margin: 8px 0;

        .postTitle_conter_itemspan1 {
          font-size: 15px;
          font-weight: 400;
          color: #989898;
        }

        .postTitle_conter_itemspan2 {
          font-size: 16px;
          font-weight: 400;
          color: #000;
        }
      }
    }
  }
}

.on_line {
  background-color: #19CDA6;
}

.off_line {
  background-color: #FE294D;
}

/*
  编辑
  */
.editHeld_conter_left {
  margin-right: 70px;
  text-align: center;
}

.editHeld_conter_right {
  flex: 1;

  .el-row {
    margin-bottom: 45px;
  }
}

::v-deep .editHeld_conter_left .avatar-uploader .el-upload {
  border: 1px solid #d9d9d9;
  border-radius: 50%;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  text-align: center;
}

// ::v-deep  .avatar-uploader .el-upload:hover {
//   border-color: #409EFF;
// }
.editHeld_conter_left .avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 160px;
  height: 160px;
  line-height: 160px;
  text-align: center;
}

.editHeld_conter_left .avatar {
  width: 160px;
  height: 160px;
  display: block;
  position: relative;

  img {
    width: 100%;
    height: 100%;
  }

  div {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #00000066;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 400;
    color: #FFFFFFAA;
  }
}
</style>
